package com.dragon.repository.domain.vo;

import com.dragon.common.model.Update;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Workflow;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@ApiModel(value = "")
public class WorkflowVO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @ApiModelProperty(value = "工作流名称")
    private String name;

    @ApiModelProperty(value = "工作流类型")
    private Integer type;

    private String jsonConfig;

    @ApiModelProperty(value = "0禁用,1开启")
    private Integer state;

    @ApiModelProperty(value = "是否默认：0否，1是")
    private Integer defaultOrNot;

    /**
     * 当前部门领导提交的表单：0 不免审，1免审
     */
    @ApiModelProperty(value = "免审:0,不免，1免审")
    private Integer exempt;

    @ApiModelProperty(value = "是否反审批： 0否 1是")
    private Integer isAnti;

    @ApiModelProperty(value = "关联字段")
    private String field;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;


    @NotNull(groups = Update.class,message = "主键不能为空")
    public static Workflow convert(WorkflowVO vo) {
        Workflow entity = new Workflow();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }
    public static List<Workflow> convertList(List<WorkflowVO> list) {
        List<Workflow> resultList = new ArrayList<>();
        for (WorkflowVO vo : list) {
            resultList.add(convert(vo));
        }
        return resultList;
    }
}
